/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package officeboost.entity;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author sorra
 */
@Entity
@Table(name="user0")
public class User implements Serializable {
    private static final Long serialVersionUID = 1L;

    private String id;
    private String name;
    private String password;
    private String introduction;
    private List<Group> groups;
    private String gender;
    private String grade;
    private String phone;
    private String email;
    private int timeoff;
    
    @Id
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    
    // 获取所有组名
    public String putGroupString(){
        String result = "";
        Iterator it = groups.iterator();
        while (it.hasNext()) {            
            Group group = (Group) it.next();
            if(result.equals("")){
                result = group.getName();
            }
            else{
                result = result + "," + group.getName();
            }
        }
        return result;
    }
    
   

//    public int getLeave() {
//        return leave;
//    }
//
//    public void setLeave(int leave) {
//        this.leave = leave;
//    }
    
    

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public int getTimeoff() {
        return timeoff;
    }

    public void setTimeoff(int timeoff) {
        this.timeoff = timeoff;
    }
    
    

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    @ManyToMany(mappedBy = "users", fetch= FetchType.EAGER)
    public List<Group> getGroups() {
        return groups;
    }

    public void setGroups(List<Group> groupList) {
        this.groups = groupList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "officeboost.entity.User[ id=" + id + " ]";
    }
}
